<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\CompanyArticleType;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class CompanyArticleTypeController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CompanyArticleType(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('title');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });

            // 禁用
            $grid->disableCreateButton();
            // 禁用删除按钮
            $grid->disableDeleteButton();
            // 禁用批量删除按钮
            $grid->disableBatchDelete();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CompanyArticleType(['companyArticle']), function (Show $show) {
            $show->field('id');
            $show->field('title');
            $show->field("company_article.description","描述");
            $show->field("company_article.content","内容")->unescape();
            $show->field("company_article.pc_content","PC端内容")->unescape();
            $show->panel()
                ->tools(function ($tools) {

                    $tools->disableList();
                    $tools->disableDelete();
                });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CompanyArticleType(['companyArticle']), function (Form $form) {
//            dd($form->model());
            $form->display('id');
            $form->text('title');
            $form->text("company_article.description","描述");
            $form->editor("company_article.content","内容")
                ->rules("required",[
                "required"=>"内容必须"
            ]);
            $form->editor("company_article.pc_content","PC端内容");
            $form->tools(function (Form\Tools $tools) {
                // 去掉删除按钮
                $tools->disableDelete();
            });
        });
    }
}
